package com.css.bjdt_core.ryxx.service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.nutz.dao.Cnd;
import org.nutz.dao.Condition;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.css.bjdt_core.reportFill.entity.ViewUnitTemplate;
import com.css.bjdt_core.reportPrepare.entity.RptTemplate;
import com.css.bjdt_core.util.PageQuerys;

@Service
public class DnDjService {
	@Autowired
	private Dao dao;

	/*public List<String> queryReportIds(String annualId) {
		Sql sql = Sqls.create("select distinct TEMPLATE_DATA_ID from $table");
		sql.vars().set("table", "RPT_CELL_DATA_" + annualId);
		sql.setCallback(new SqlCallback() {

			@Override
			public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
				// TODO Auto-generated method stub
				List<String> list = new ArrayList<String>();
				while (rs.next()) {
					list.add(rs.getString("TEMPLATE_DATA_ID"));
				}
				return list;
			}
		});
		dao.execute(sql);
		return sql.getList(String.class);
	}

	//	public List<RptUnitTemplateRel> getTemplateRel(String annualId, String unitId, List<String> templateIds) {
	//		List<RptUnitTemplateRel> unitTemplates = dao.query(RptUnitTemplateRel.class,
	//				Cnd.where("ANNUALID", "=", annualId).and("UNITID", "=", unitId).and("ID", "IN", templateIds));
	//		return unitTemplates;
	//	}

	public Mryinfo getTemplatesById(String id) {
		RptTemplate unitTemplates = dao.fetch(RptTemplate.class, id);
		return unitTemplates;
	}

	//获得所有报表
	public Map queryTemplates(Condition cnd, int pageNum, int pageSize) {
		Map m = PageQuerys.ligerGridQuery(dao, ViewUnitTemplate.class, cnd, pageNum, pageSize);
		return m;
	}

	public Map queryPage(List<String> idList, int pageNum, int pageSize) {
		Condition cnd = null;
		if (idList.size() != 0) {
			cnd = Cnd.where("TEMPLATEID", "IN", idList);
		} else {
			cnd = Cnd.where("TEMPLATEID", "=", "-1");
		}
		return PageQuerys.ligerGridQuery(dao, RptTemplate.class, cnd, pageNum, pageSize);
	}

	public List<ViewUnitTemplate> queryPrintAll(String batchId) {
		List<ViewUnitTemplate> list = dao.query(ViewUnitTemplate.class,
				Cnd.where("BATCH_ID", "=", batchId).asc("ORDERID").asc("TEMPLATEORDERID"));
		return list;
	}
*/
}
